package com.example.lcode.binary;

import java.util.*;

/**
 * @version 1.0
 * @author: ChuJie_Lin
 * @since: 2021-11-17 12:52
 **/
public class Question532 {

    public int findPairs(int[] nums, int k) {
        Map<Integer,Integer> map=new HashMap<>();
        int count=0;
        if(k<0)return count;
        for(int i=0;i<nums.length;i++){
            map.putIfAbsent(nums[i],0);
            map.put(nums[i],map.get(nums[i])+1);
        }
        for(int i:map.keySet()){
            if(k==0){
                if(map.get(i)>1)
                    count++;
            }
            else if(map.containsKey(i+k)){
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        Question532 question532 = new Question532();
        int []arr = {1, 3, 1, 5, 4};
        int k = 0;
        int pairs = question532.findPairs(arr, k);
        System.out.println(pairs);
    }

}
